import os


def watchlogs(logsfilename):

    if not os.path.exists(logsfilename):
        with open(logsfilename, "w") as file:
            pass  # 什么也不做，只是创建一个空文件
        return None

    file = open(logsfilename, "r")
    content = file.read()
    content = content.strip()
    file.close()
    if content == "":
        return None

    lines = content.split("\n")  # 分隔符为换行符
    outlines = []
    if len(lines) == 0:
        return None

    for i, line in enumerate(lines):
        outlines.append(str(i + 1) + ". " + line)

    outlines = outlines[-1000:]
    outlines.reverse()
    reverse_content = "\n".join(outlines)
    # print("====================================\n")
    # print(reverse_content)
    return reverse_content


def writeNull(logsfilename):
    with open(logsfilename, "w") as file:
        file.write("")
        file.close()
